Skip to content

Conversation

@pashu123
Copy link
Member

@pashu123 pashu123 commented Nov 19, 2024

If the target op is an scf.forall op which is erased by rewriteOneForallCommonImpl method, it leads to an ASAN failure since it's used later by replaceUnitMappingIdsHelper fn.

Follows the same philosophy as done here:

Block *parentBlock = forallOp->getBlock();
and later passed to the same method here:
replaceUnitMappingIdsHelper<BlockDimOp>(rewriter, loc, parentBlock, zero,

If the target op is an scf.forall op which is erased by
`rewriteOneForallCommonImpl` method it leads to asan failure since it's
used later by `replaceUnitMappingIdsHelper` fn.

Follows the same philosophy as done here:
https://github.com/llvm/llvm-project/blob/aff98e4be05a1060e489ce62a88ee0ff365e571a/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp#L599
and later passed to the same method here:
https://github.com/llvm/llvm-project/blob/aff98e4be05a1060e489ce62a88ee0ff365e571a/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp#L629
@llvmbot
Copy link
Member

llvmbot commented Nov 19, 2024

@llvm/pr-subscribers-mlir

Author: Prashant Kumar (pashu123)

Changes

If the target op is an scf.forall op which is erased by rewriteOneForallCommonImpl method it leads to asan failure since it's used later by replaceUnitMappingIdsHelper fn.

Follows the same philosophy as done here:

Block *parentBlock = forallOp->getBlock();
and later passed to the same method here:
replaceUnitMappingIdsHelper<BlockDimOp>(rewriter, loc, parentBlock, zero,


Full diff: https://github.com/llvm/llvm-project/pull/116816.diff

1 Files Affected:

  • (modified) mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp (+3-1)
diff --git a/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp b/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp
index 1528da914d546b..e836820c960339 100644
--- a/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp
+++ b/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp
@@ -853,6 +853,8 @@ DiagnosedSilenceableFailure mlir::transform::gpu::mapNestedForallToThreadsImpl(
                                  "requires size-3 thread mapping");
   }
 
+  Block *parentBlock = target->getBlock();
+
   // Create an early zero index value for replacements.
   Location loc = target->getLoc();
   Value zero = rewriter.create<arith::ConstantIndexOp>(loc, 0);
@@ -872,7 +874,7 @@ DiagnosedSilenceableFailure mlir::transform::gpu::mapNestedForallToThreadsImpl(
 
   // Replace ids of dimensions known to be 1 by 0 to simplify the IR.
   // Here, the result of mapping determines the available mapping sizes.
-  replaceUnitMappingIdsHelper<ThreadIdOp>(rewriter, loc, target, zero,
+  replaceUnitMappingIdsHelper<ThreadIdOp>(rewriter, loc, parentBlock, zero,
                                           blockDims);
 
   return DiagnosedSilenceableFailure::success();

@llvmbot
Copy link
Member

llvmbot commented Nov 19, 2024

@llvm/pr-subscribers-mlir-gpu

Author: Prashant Kumar (pashu123)

Changes

If the target op is an scf.forall op which is erased by rewriteOneForallCommonImpl method it leads to asan failure since it's used later by replaceUnitMappingIdsHelper fn.

Follows the same philosophy as done here:

Block *parentBlock = forallOp->getBlock();
and later passed to the same method here:
replaceUnitMappingIdsHelper<BlockDimOp>(rewriter, loc, parentBlock, zero,


Full diff: https://github.com/llvm/llvm-project/pull/116816.diff

1 Files Affected:

  • (modified) mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp (+3-1)
diff --git a/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp b/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp
index 1528da914d546b..e836820c960339 100644
--- a/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp
+++ b/mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp
@@ -853,6 +853,8 @@ DiagnosedSilenceableFailure mlir::transform::gpu::mapNestedForallToThreadsImpl(
                                  "requires size-3 thread mapping");
   }
 
+  Block *parentBlock = target->getBlock();
+
   // Create an early zero index value for replacements.
   Location loc = target->getLoc();
   Value zero = rewriter.create<arith::ConstantIndexOp>(loc, 0);
@@ -872,7 +874,7 @@ DiagnosedSilenceableFailure mlir::transform::gpu::mapNestedForallToThreadsImpl(
 
   // Replace ids of dimensions known to be 1 by 0 to simplify the IR.
   // Here, the result of mapping determines the available mapping sizes.
-  replaceUnitMappingIdsHelper<ThreadIdOp>(rewriter, loc, target, zero,
+  replaceUnitMappingIdsHelper<ThreadIdOp>(rewriter, loc, parentBlock, zero,
                                           blockDims);
 
   return DiagnosedSilenceableFailure::success();

@pashu123 pashu123 requested a review from Max191 November 19, 2024 14:55
@joker-eph
Copy link
Collaborator

Is there an existing tests failing with ASAN?

@pashu123
Copy link
Member Author

Is there an existing tests failing with ASAN?

Tests failed in the downstream project, but I'll add them here.

@pashu123
Copy link
Member Author

Is there an existing tests failing with ASAN?

I'm curious if we need to add tests for ASAN failures because I believe this patch addresses a fundamental issue.

@joker-eph
Copy link
Collaborator

This is a problem of test coverage.
Many patch fixes crashes, assertions, and other similar fundamental issues but we're pretty consistent with adding test most of the time I think.

@pashu123
Copy link
Member Author

@joker-eph @ftynse Do you know how to add tests for this?

transform.gpu.map_nested_forall_to_threads %gpuLaunch block_dims = [32, 4, 1] : (!transform.any_op) -> !transform.any_op
transform.gpu.map_nested_forall_to_threads always expect a gpu.launch op. The problem happens when we directly use
DiagnosedSilenceableFailure mlir::transform::gpu::mapNestedForallToThreadsImpl(
without the check.

@pashu123 pashu123 requested a review from hanhanW November 21, 2024 16:50
Copy link
Member

@ftynse ftynse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take the downstream tests that triggered the asan issue, minimize it by removing downstream-specific parts, and put it somewhere it can run. Ideally, it would be a "unit test", i.e, a .mlir file running one pass and checking the output. Many MLIR integrators are running all tests under asan and would have seen the failure had it had the corresponding test.

Regardless of that, the change itself looks off to me. It calls replaceUnitMappingIdsHelper on the parent block of a target, which breaks the fundamental assumption of the transform dialect (and passes by the way, imaging target is the root operation of the interpreter pass).

@pashu123
Copy link
Member Author

The problem was with the downstream calling convention. I am closing this.

@pashu123 pashu123 closed this Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants